package com.xjzd.http;

import okhttp3.ConnectionPool;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

public class OkHttpDemo {

    public static void main(String[] args) throws IOException {

        ConnectionPool connectionPool = new ConnectionPool(10, 1000, TimeUnit.SECONDS);

        OkHttpClient client = new OkHttpClient.Builder()
                .connectTimeout(3, TimeUnit.SECONDS)
                .readTimeout(3, TimeUnit.SECONDS)
                .writeTimeout(3, TimeUnit.SECONDS)
                .connectionPool(connectionPool)
                .build();

        Request request = new Request.Builder()
                .get()
                .url("https://www.baidu.com")
                .build();
        for (int i = 0; i < 10; i++) {
            Response response = client.newCall(request).execute();
            System.out.println(response.body().string());
            System.out.println(response.header("Connection"));
        }
        System.in.read();
    }
}
